package top.shiyiri.threading;

/**
 * 例：创建三个窗口卖票，总票数为 100 张，使用实现 Runnable 接口的方式
 * 存在线程安全问题，待解决
 * @author Aunean
 * @date 2021/12/25
 */
class Window1 implements Runnable {
    private int ticket = 100;

    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                System.out.println(Thread.currentThread().getName() + ":" + ticket);
                ticket --;
            } else {
                break;
            }
        }
    }
}
public class WindowTest1 {

    public static void main(String[] args) {

        Window1 w1 = new Window1();

        Thread t1 = new Thread(w1);
        Thread t2 = new Thread(w1);
        Thread t3 = new Thread(w1);

        t1.start();
        t2.start();
        t3.start();
    }
}
